Dropdown List Handling

Redirect to Another Page when Dropdown Field Changes

Description
This example shows how to redirect to another page when dropdown field changes. If a user selects the dropdown list, the web application can redirect the user to a specific web page.
Variables
Record Control
Select record control class in which the dropdown list control is present
Dropdown List Control
Select the dropdown list control
Applies to
RecordControl class
Code
 

/// 
/// Add a new event handler for the Load Event  
/// 
public ${Record Control}()
{
    // The following line will be inserted inside the
    // constructor for page class.    
    this.Load += new System.EventHandler(${Record Control}_Load);
}

/// 
/// Overrides SelectedIndexChanged event to redirect to another page.
/// 
protected override void ${Dropdown List Control}_SelectedIndexChanged(object sender, EventArgs args)
{    
    // retrieve the selected value of dropdown list control.
    string selectedValue = this.${Dropdown List Control}.SelectedItem.Text;

    // Add custom code to check for the value. Here is an example of a switch statement for multiple 
    // redirects when certain values are selected for the dropdown list.
	
      switch (selectedValue) { 
        // Here replace value1, value2 with actual values
        case "value1": 
			this.Page.Response.Redirect("../OtherPages/SomeOtherPage1.aspx"); 
			break;
        case "value2": 
            this.Page.Response.Redirect("../OtherPages/SomeOtherPage2.aspx");    
            break;        
        default: 
            this.Page.Response.Redirect("../OtherPages/SomeOtherDefaultPage.aspx"); 
            break; 
        }	        

}

/// 
/// This method sets up a event handler for a selected index changed event.
/// 
private void ${Record Control}_Load(object sender , System.EventArgs e)
{
    this.${Dropdown List Control}.AutoPostBack = true;
    this.${Dropdown List Control}.SelectedIndexChanged += new System.EventHandler(${Dropdown List Control}_SelectedIndexChanged);
}
    

Terms of Service Privacy Statement